﻿using DSPL.Contracts;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DSPL.Common
{
    /// <summary>
    /// Common Textbox tool for handeling Cost Details
    /// </summary>
    public partial class TxtCostCenter : UserControl
    {
        public TxtCostCenter()
        {
            InitializeComponent();
        }

        #region Declaring Properties

        #region General Properties

        public HelpNames HelpName
        {
            get { return (HelpNames)GetValue(HelpNameProperty); }
            set { SetValue(HelpNameProperty, value); }
        }

        public object CostKeyValue
        {
            get { return (object)GetValue(CostKeyValueProperty); }
            set { SetValue(CostKeyValueProperty, value); }
        }

        public string KeyFieldName
        {
            get { return (string)GetValue(KeyFieldNameProperty); }
            set { SetValue(KeyFieldNameProperty, value); }
        }

        public string KeyFieldType
        {
            get { return (string)GetValue(KeyFieldTypeProperty); }
            set { SetValue(KeyFieldTypeProperty, value); }
        }

        public DataRow SelectedDataRow
        {
            get { return (DataRow)GetValue(SelectedDataRowProperty); }
            set { SetValue(SelectedDataRowProperty, value); }
        }

        public Modes ParentFormMode
        {
            get { return (Modes)GetValue(ParentFormModeProperty); }
            set { SetValue(ParentFormModeProperty, value); }
        }

        public bool IsMandatory
        {
            get { return (bool)GetValue(IsMandatoryProperty); }
            set { SetValue(IsMandatoryProperty, value); }
        }

        public string FilterString
        {
            get { return (string)GetValue(FilterStringProperty); }
            set { SetValue(FilterStringProperty, value); }
        }

        public string CostCon
        {
            get { return (string)GetValue(CostConProperty); }
            set { SetValue(CostConProperty, value); }
        }

        #endregion

        #region txtCode Properties

        public Visibility CodeVisibility
        {
            get { return (Visibility)GetValue(CodeVisibilityProperty); }
            set { SetValue(CodeVisibilityProperty, value); }
        }

        public bool CodeEnable
        {
            get { return (bool)GetValue(CodeEnableProperty); }
            set { SetValue(CodeEnableProperty, value); }
        }

        public string CostCode
        {
            get { return (string)GetValue(CostCodeProperty); }
            set { SetValue(CostCodeProperty, value); }
        }

        public int CodeColumnSpan
        {
            get { return (int)GetValue(CodeColumnSpanProperty); }
            set { SetValue(CodeColumnSpanProperty, value); }
        }

        public string CostCodeFieldName
        {
            get { return (string)GetValue(CostCodeFieldNameProperty); }
            set { SetValue(CostCodeFieldNameProperty, value); }
        }
                

        #endregion

        #region txtDescription Properties

        public Visibility DescriptionVisibility
        {
            get { return (Visibility)GetValue(DescriptionVisibilityProperty); }
            set { SetValue(DescriptionVisibilityProperty, value); }
        }

        public bool DescriptionEnable
        {
            get { return (bool)GetValue(DescriptionEnableProperty); }
            set { SetValue(DescriptionEnableProperty, value); }
        }

        public string CostDescription
        {
            get { return (string)GetValue(CostDescriptionProperty); }
            set { SetValue(CostDescriptionProperty, value); }
        }

        public int DescriptionColumnSpan
        {
            get { return (int)GetValue(DescriptionColumnSpanProperty); }
            set { SetValue(DescriptionColumnSpanProperty, value); }
        }

        public int DescriptionColumn
        {
            get { return (int)GetValue(DescriptionColumnProperty); }
            set { SetValue(DescriptionColumnProperty, value); }
        }

        public bool IsFocus
        {
            get { return (bool)GetValue(IsFocusProperty); }
            set { SetValue(IsFocusProperty, value); }
        }

        public string CostDescriptionFieldName
        {
            get { return (string)GetValue(CostDescriptionFieldNameProperty); }
            set { SetValue(CostDescriptionFieldNameProperty, value); }
        }
        #endregion

        #region Other Cost Details Properties

        public string CodeLevel1
        {
            get { return (string)GetValue(CodeLevel1Property); }
            set { SetValue(CodeLevel1Property, value); }
        }

        public string CodeLevel2
        {
            get { return (string)GetValue(CodeLevel2Property); }
            set { SetValue(CodeLevel2Property, value); }
        }

        public string CodeLevel3
        {
            get { return (string)GetValue(CodeLevel3Property); }
            set { SetValue(CodeLevel3Property, value); }
        }

        public string CodeLevel4
        {
            get { return (string)GetValue(CodeLevel4Property); }
            set { SetValue(CodeLevel4Property, value); }
        }

        public string CodeLevel5
        {
            get { return (string)GetValue(CodeLevel5Property); }
            set { SetValue(CodeLevel5Property, value); }
        }

        public string CodeLevel6
        {
            get { return (string)GetValue(CodeLevel6Property); }
            set { SetValue(CodeLevel6Property, value); }
        }

        public string CodeLevel7
        {
            get { return (string)GetValue(CodeLevel7Property); }
            set { SetValue(CodeLevel7Property, value); }
        }

        public string CodeLevel8
        {
            get { return (string)GetValue(CodeLevel8Property); }
            set { SetValue(CodeLevel8Property, value); }
        }

        public int Level1
        {
            get { return (int)GetValue(Level1Property); }
            set { SetValue(Level1Property, value); }
        }

        public int Level2
        {
            get { return (int)GetValue(Level2Property); }
            set { SetValue(Level2Property, value); }
        }

        public int Level3
        {
            get { return (int)GetValue(Level3Property); }
            set { SetValue(Level3Property, value); }
        }

        public int Level4
        {
            get { return (int)GetValue(Level4Property); }
            set { SetValue(Level4Property, value); }
        }

        public int Level5
        {
            get { return (int)GetValue(Level5Property); }
            set { SetValue(Level5Property, value); }
        }

        public int Level6
        {
            get { return (int)GetValue(Level6Property); }
            set { SetValue(Level6Property, value); }
        }

        public int Level7
        {
            get { return (int)GetValue(Level7Property); }
            set { SetValue(Level7Property, value); }
        }

        public int Level8
        {
            get { return (int)GetValue(Level8Property); }
            set { SetValue(Level8Property, value); }
        }

        #endregion

        #endregion

        #region Dependency Properties

        public static readonly DependencyProperty HelpNameProperty = DependencyProperty.Register("HelpName", typeof(HelpNames), typeof(TxtCostCenter), new PropertyMetadata(HelpNames.CostCenterDescriptiveHelp));

        public static readonly DependencyProperty CostKeyValueProperty = DependencyProperty.Register("CostKeyValue", typeof(object), typeof(TxtCostCenter), new PropertyMetadata(null));

        public static readonly DependencyProperty KeyFieldNameProperty = DependencyProperty.Register("KeyFieldName", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty KeyFieldTypeProperty = DependencyProperty.Register("KeyFieldType", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(null));

        public static readonly DependencyProperty SelectedDataRowProperty = DependencyProperty.Register("SelectedDataRow", typeof(DataRow), typeof(TxtCostCenter), new PropertyMetadata(null));

        public static readonly DependencyProperty CodeVisibilityProperty = DependencyProperty.Register("CodeVisibility", typeof(Visibility), typeof(TxtCostCenter), new PropertyMetadata(Visibility.Visible));

        public static readonly DependencyProperty CodeEnableProperty = DependencyProperty.Register("CodeEnable", typeof(bool), typeof(TxtCostCenter), new PropertyMetadata(true));

        public static readonly DependencyProperty CostCodeProperty = DependencyProperty.Register("CostCode", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty CostCodeFieldNameProperty = DependencyProperty.Register("CostCodeFieldName", typeof(string), typeof(TxtCostCenter), new PropertyMetadata("CostCode"));

        public static readonly DependencyProperty CostDescriptionFieldNameProperty = DependencyProperty.Register("CostDescriptionFieldName", typeof(string), typeof(TxtCostCenter), new PropertyMetadata("CostName"));


        public static readonly DependencyProperty DescriptionVisibilityProperty = DependencyProperty.Register("DescriptionVisibility", typeof(Visibility), typeof(TxtCostCenter), new PropertyMetadata(Visibility.Visible));

        public static readonly DependencyProperty DescriptionEnableProperty = DependencyProperty.Register("DescriptionEnable", typeof(bool), typeof(TxtCostCenter), new PropertyMetadata(false));

        public static readonly DependencyProperty CostDescriptionProperty = DependencyProperty.Register("CostDescription", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty ParentFormModeProperty = DependencyProperty.Register("ParentFormMode", typeof(Modes), typeof(TxtCostCenter), new PropertyMetadata(Modes.Undo));

        public static readonly DependencyProperty IsMandatoryProperty = DependencyProperty.Register("IsMandatory", typeof(bool), typeof(TxtCostCenter), new PropertyMetadata(false));

        public static readonly DependencyProperty CodeColumnSpanProperty = DependencyProperty.Register("CodeColumnSpan", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(1));

        public static readonly DependencyProperty DescriptionColumnSpanProperty = DependencyProperty.Register("DescriptionColumnSpan", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(1));

        public static readonly DependencyProperty DescriptionColumnProperty = DependencyProperty.Register("DescriptionColumn", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(1));

        public static readonly DependencyProperty IsFocusProperty = DependencyProperty.Register("IsFocus", typeof(bool), typeof(TxtCostCenter), new PropertyMetadata(false));

        public static readonly DependencyProperty CostRateProperty = DependencyProperty.Register("CostRate", typeof(double), typeof(TxtCostCenter), new PropertyMetadata(0.00));

        public static readonly DependencyProperty CostPrecentageProperty = DependencyProperty.Register("CostPrecentage", typeof(double), typeof(TxtCostCenter), new PropertyMetadata(0.00));

        public static readonly DependencyProperty FilterStringProperty = DependencyProperty.Register("FilterString", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty CodeLevel1Property = DependencyProperty.Register("CodeLevel1", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty CodeLevel2Property = DependencyProperty.Register("CodeLevel2", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty CodeLevel3Property = DependencyProperty.Register("CodeLevel3", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty CodeLevel4Property = DependencyProperty.Register("CodeLevel4", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty CodeLevel5Property = DependencyProperty.Register("CodeLevel5", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty CodeLevel6Property = DependencyProperty.Register("CodeLevel6", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty CodeLevel7Property = DependencyProperty.Register("CodeLevel7", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty CodeLevel8Property = DependencyProperty.Register("CodeLevel8", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        public static readonly DependencyProperty Level1Property = DependencyProperty.Register("Level1", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(0));

        public static readonly DependencyProperty Level2Property = DependencyProperty.Register("Level2", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(0));

        public static readonly DependencyProperty Level3Property = DependencyProperty.Register("Level3", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(0));

        public static readonly DependencyProperty Level4Property = DependencyProperty.Register("Level4", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(0));

        public static readonly DependencyProperty Level5Property = DependencyProperty.Register("Level5", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(0));

        public static readonly DependencyProperty Level6Property = DependencyProperty.Register("Level6", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(0));

        public static readonly DependencyProperty Level7Property = DependencyProperty.Register("Level7", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(0));

        public static readonly DependencyProperty Level8Property = DependencyProperty.Register("Level8", typeof(int), typeof(TxtCostCenter), new PropertyMetadata(0));

        public static readonly DependencyProperty CostConProperty = DependencyProperty.Register("CostCon", typeof(string), typeof(TxtCostCenter), new PropertyMetadata(string.Empty));

        #endregion

        #region Exposable Event Handlers

        public event EventHandler<EventArgs> RefreshCostRelatedData;             //use to refresh data regarding Customer Master Text box

        #endregion

        #region Internal Events

        private void RefreshAttachedObjects(object sender, EventArgs e)
        {
            SetCostData();

            if (RefreshCostRelatedData != null)
                RefreshCostRelatedData(sender, e);
        }

        private void SetCostData()
        {
            if (SelectedDataRow != null && HelpName == HelpNames.CostCenterDescriptiveHelp)
            {
                CostCon = SelectedDataRow["CostCon"].ToString();
                Level1 = (int)SelectedDataRow["level1"];
                Level2 = (int)SelectedDataRow["level2"];
                Level3 = (int)SelectedDataRow["level3"];
                Level4 = (int)SelectedDataRow["level4"];
                Level5 = (int)SelectedDataRow["level5"];
                Level6 = (int)SelectedDataRow["level6"];
                Level7 = (int)SelectedDataRow["level7"];
                Level8 = (int)SelectedDataRow["level8"];
                CodeLevel1 = SelectedDataRow["CodeLevel1"].ToString();
                CodeLevel2 = SelectedDataRow["CodeLevel2"].ToString();
                CodeLevel3 = SelectedDataRow["CodeLevel3"].ToString();
                CodeLevel4 = SelectedDataRow["CodeLevel4"].ToString();
                CodeLevel5 = SelectedDataRow["CodeLevel5"].ToString();
                CodeLevel6 = SelectedDataRow["CodeLevel6"].ToString();
                CodeLevel7 = SelectedDataRow["CodeLevel7"].ToString();
                CodeLevel8 = SelectedDataRow["CodeLevel8"].ToString();
            }
            else
                ClearData();


        }

        private void ClearData()
        {
            CostCon = string.Empty;
            Level1 = 0;
            Level2 = 0;
            Level3 = 0;
            Level4 = 0;
            Level5 = 0;
            Level6 = 0;
            Level7 = 0;
            Level8 = 0;
            CodeLevel1 = string.Empty;
            CodeLevel2 = string.Empty;
            CodeLevel3 = string.Empty;
            CodeLevel4 = string.Empty;
            CodeLevel5 = string.Empty;
            CodeLevel6 = string.Empty;
            CodeLevel7 = string.Empty;
            CodeLevel8 = string.Empty;
        }

        #endregion
    }
}
